package com.ruoyi.shopping.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shopping.domain.CommodityLikeEvaluate;
import com.ruoyi.shopping.service.ICommodityLikeEvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评价点赞管理Controller
 * 
 * @author fxy
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/shopping/LikeEvaluate")
public class CommodityLikeEvaluateController extends BaseController
{
    @Autowired
    private ICommodityLikeEvaluateService commodityLikeEvaluateService;

    /**
     * 查询评价点赞管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:LikeEvaluate:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommodityLikeEvaluate commodityLikeEvaluate)
    {
        startPage();
        List<CommodityLikeEvaluate> list = commodityLikeEvaluateService.selectCommodityLikeEvaluateList(commodityLikeEvaluate);
        return getDataTable(list);
    }

    /**
     * 导出评价点赞管理列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:LikeEvaluate:export')")
    @Log(title = "评价点赞管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommodityLikeEvaluate commodityLikeEvaluate)
    {
        List<CommodityLikeEvaluate> list = commodityLikeEvaluateService.selectCommodityLikeEvaluateList(commodityLikeEvaluate);
        ExcelUtil<CommodityLikeEvaluate> util = new ExcelUtil<CommodityLikeEvaluate>(CommodityLikeEvaluate.class);
        util.exportExcel(response, list, "评价点赞管理数据");
    }

    /**
     * 获取评价点赞管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:LikeEvaluate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(commodityLikeEvaluateService.selectCommodityLikeEvaluateById(id));
    }

    /**
     * 新增评价点赞管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:LikeEvaluate:add')")
    @Log(title = "评价点赞管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommodityLikeEvaluate commodityLikeEvaluate)
    {
        return toAjax(commodityLikeEvaluateService.insertCommodityLikeEvaluate(commodityLikeEvaluate));
    }

    //取消点赞
    @PreAuthorize("@ss.hasPermi('shopping:LikeEvaluate:remove')")
    @Log(title = "评价点赞管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/CId")
    public AjaxResult removeCollection(@RequestBody  CommodityLikeEvaluate commodityLikeEvaluate) {
        return toAjax(commodityLikeEvaluateService.deleteCommodityLikeEvaluate(commodityLikeEvaluate));
    }
    //查询该评价是否被当前用户点赞
    @PreAuthorize("@ss.hasPermi('shopping:LikeEvaluate:query')")
    @GetMapping(value = "/isZan")
    public AjaxResult isCollection( CommodityLikeEvaluate commodityLikeEvaluate) {
        return success(commodityLikeEvaluateService.queryByCCId(commodityLikeEvaluate));
    }

    /**
     * 修改评价点赞管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:LikeEvaluate:edit')")
    @Log(title = "评价点赞管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommodityLikeEvaluate commodityLikeEvaluate)
    {
        return toAjax(commodityLikeEvaluateService.updateCommodityLikeEvaluate(commodityLikeEvaluate));
    }

    /**
     * 删除评价点赞管理
     */
    @PreAuthorize("@ss.hasPermi('shopping:LikeEvaluate:remove')")
    @Log(title = "评价点赞管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(commodityLikeEvaluateService.deleteCommodityLikeEvaluateByIds(ids));
    }
}
